import * as api from "./api";
import {CreateCrudOptionsProps, CreateCrudOptionsRet, dict, UserPageQuery} from "@fast-crud/fast-crud";

export default function ({expose}: CreateCrudOptionsProps): CreateCrudOptionsRet {
    const pageRequest = async (query: UserPageQuery) => {
        return await api.GetList(query);
    };
    const editRequest = async ({form, row}) => {
        if (form.id == null) {
            form.id = row.id;
        }
        return await api.UpdateObj(form);
    };
    const delRequest = async ({row}) => {
        return await api.DelObj(row.id);
    };

    const addRequest = async ({form}) => {
        return await api.AddObj(form);
    };

    const statusDict = dict({
        data: [
            {value: "info", label: "info", color: "success"},
            {value: "debug", label: "debug", color: null},
            {value: "warn", label: "warn", color: "warn"},
            {value: "error", label: "error", color: "error"},
            {value: "fatal", label: "fatal", color: "error"}
        ]
    });

    return {
        crudOptions: {
            request: {
                pageRequest,
                addRequest,
                editRequest,
                delRequest
            },
            columns: {
                id: {
                    title: "ID",
                    key: "id",
                    type: "number",
                    column: {
                        width: 50
                    },
                    form: {
                        show: false
                    }
                },
                status: {
                    title: "日志记录类型",
                    search: {show: true},
                    dict: statusDict,
                    type: "dict-select"
                },
                info: {
                    title: "日志内容",
                    type: "text",
                },
                create_time: {
                    title: "日志记录时间",
                    type: "datetime",
                }
            }
        }
    };
}
